package cn.edu.zafu.bigdata.x.zhaobolei.Third;

abstract class Shape {

    public abstract double area();

    public abstract double perimeter();

    public final void display() {
        System.out.println("形状的类型: " + getClass().getSimpleName() +
                ", 形状的面积: " + area() +
                ", 形状的周长: " + perimeter());
    }
}

class Circle extends Shape {
    private double radius;

    public Circle(double radius) {
        this.radius = radius;
    }

    @Override
    public double area() {
        return Math.PI * radius * radius;
    }

    @Override
    public double perimeter() {
        return 2 * Math.PI * radius;
    }
}

class Rectangle extends Shape {
    private double length;
    private double width;

    public Rectangle(double length, double width) {
        this.length = length;
        this.width = width;
    }

    @Override
    public double area() {
        return length * width;
    }

    @Override
    public double perimeter() {
        return 2 * (length + width);
    }
}

public class TestShape {
    public static void main(String[] args) {
        Circle circle = new Circle(5);
        Rectangle rectangle = new Rectangle(2, 4);

        circle.display();
        rectangle.display();
    }
}
